package cn.doitedu.hive.udf;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FindEvents {

    /*public static String[] findFirstFactor(String[] eList,String[] targets){

        ArrayList<String> lst = new ArrayList<>();
        if(Arrays.binarySearch(eList,targets[0])>0){

        }

    }*/

    public static int findFirstFactor(String[] arr,String[] tar) {

        List<String> arrList = Arrays.asList(arr);

        int firstFactorIndex = 0;
        for(int i=0;i<tar.length;i++) {
            int idx = arrList.indexOf(tar[i]);
            if(idx>=firstFactorIndex){
                firstFactorIndex = idx;
            }
        }

        return firstFactorIndex>=0?firstFactorIndex:-1;
    }


    public static int findFirstFactor2(String arrStr,String tarStr) {

        List<String> arrList = Arrays.asList(arrStr.split(","));
        String[] tar = tarStr.split(",");

        int firstFactorIndex = -1;;
        for(int i=0;i<tar.length;i++) {
            int idx = arrList.indexOf(tar[i]);
            if(idx>=0 && firstFactorIndex<0){
                firstFactorIndex = i;
            }else if(firstFactorIndex>=0 && idx>=0 && idx<firstFactorIndex){
                firstFactorIndex = i;
            }

        }

        return firstFactorIndex;
    }

    public static void main(String[] args) {
        int j = findFirstFactor2("c,b,c,a,c", "e,x");
        System.out.println(j);

        int x = Arrays.asList("a,b,c".split(",")).indexOf("e");
        System.out.println(x);
    }

}
